import { libs } from '@bairong/vix'

const { parseTime } = libs.conversion

// eslint-disable-next-line import/prefer-default-export
export const convertTime = (obj, originKey, targetKeys, time) => {
  const [keyStart, keyEnd] = targetKeys
  obj[keyStart] = parseTime(obj[originKey][0], 'YYYY-MM-DD')
  obj[keyEnd] = parseTime(obj[originKey][1], 'YYYY-MM-DD')

  if (time) {
    obj[keyStart] = `${obj[keyStart]} 00:00:00`
    obj[keyEnd] = `${obj[keyEnd]} 23:59:59`
  }

  delete obj[originKey]
}
